﻿namespace pptpclient
{
    using DotRas;
    using Hardcodet.Wpf.TaskbarNotification;
    using System;
    using System.CodeDom.Compiler;
    using System.Collections;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using System.ComponentModel;
    using System.Configuration;
    using System.Diagnostics;
    using System.Globalization;
    using System.IO;
    using System.Net;
    using System.Runtime.InteropServices;
    using System.Security.Cryptography;
    using System.Text;
    using System.Threading;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Input;
    using System.Windows.Markup;

    [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
    public class MainWindow : Window, IComponentConnector
    {
        private bool _contentLoaded;
        private static RasPhoneBook AllUsersPhoneBook = new RasPhoneBook();
        private bool AllUsersPhoneBookOpened;
        internal Button buttonDisconnect;
        internal Button buttonLogin;
        internal Button buttonLogin2;
        internal Button buttonLogout;
        internal Button buttonUpdate;
        internal Button buttonUpdateIP;
        internal CheckBox checkBoxAutoLogin;
        internal CheckBox checkBoxRememberChoise;
        internal CheckBox checkBoxSavePassword;
        internal CheckBox checkBoxShowPassword;
        internal ComboBox comboBoxConnections;
        internal ComboBox comboBoxLang;
        private SynchronizationContext context;
        internal Grid grid1;
        internal Grid grid2;
        internal TaskbarIcon icTray;
        internal Image image2;
        internal Label label1;
        internal TextBlock labelForgot;
        internal Label labelIP;
        internal Label labelLogin;
        internal Label labelPassword;
        internal TextBlock labelRegistration;
        internal Label labelStatus;
        private string lang = "";
        internal MenuItem MenuItemCheckIP;
        internal MenuItem MenuItemExit;
        internal MenuItem MenuItemShow;
        internal TextBox textBoxLogin;
        internal PasswordBox textBoxPassP;
        internal TextBox textBoxPassT;

        public MainWindow()
        {
            this.InitializeComponent();
            this.labelStatus.Content = "";
            System.Configuration.Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            this.lang = configuration.AppSettings.Settings["Language"].Value;
            if (string.IsNullOrEmpty(this.lang))
            {
                this.lang = (CultureInfo.CurrentCulture.Name == "ru-RU") ? "ru" : "en";
            }
            if (this.lang == "en")
            {
                this.comboBoxLang.SelectedIndex = 1;
                this.MenuItemShow.Header = "Show";
                this.labelIP.Content = "Check IP...";
            }
            if (this.lang == "ru")
            {
                this.comboBoxLang.SelectedIndex = 0;
                this.MenuItemShow.Header = "Показать";
                this.labelIP.Content = "Проверить IP...";
            }
            this.CheckLang();
        }

        [DebuggerNonUserCode]
        internal Delegate _CreateDelegate(Type delegateType, string handler)
        {
            return Delegate.CreateDelegate(delegateType, this, handler);
        }

        private void buttonLogin_Click(object sender, RoutedEventArgs e)
        {
            Thread thread = new Thread(delegate (object ob) {
                SendOrPostCallback callback = null;
                SendOrPostCallback callback2 = null;
                SendOrPostCallback callback3 = null;
                SendOrPostCallback callback4 = null;
                SendOrPostCallback callback5 = null;
                this.context.Send(d => this.grid1.IsEnabled = false, null);
                this.context.Send(d => this.grid2.IsEnabled = false, null);
                List<string> list = (List<string>) ob;
                string str = this.zapros(list[0], list[1]);
                if (str != "isError")
                {
                    if ((!string.IsNullOrEmpty(str) && !str.Contains("nopptp")) && !str.Contains("nolicense"))
                    {
                        if (this.lang == "en")
                        {
                            if (callback == null)
                            {
                                callback = d => base.Title = "TheSafety.US – PPTP Wizard";
                            }
                            this.context.Send(callback, null);
                        }
                        if (this.lang == "ru")
                        {
                            if (callback2 == null)
                            {
                                callback2 = d => base.Title = "TheSafety.US – Мастер PPTP";
                            }
                            this.context.Send(callback2, null);
                        }
                        string[] strArray = str.Split(new char[] { '\n' });
                        if (callback3 == null)
                        {
                            callback3 = d => this.comboBoxConnections.Items.Clear();
                        }
                        this.context.Send(callback3, null);
                        System.Configuration.Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                        int num = -1;
                        int selectIndex = 0;
                        foreach (string str2 in strArray)
                        {
                            string[] strArray2 = str2.Split(new char[] { '\t' });
                            Conn c = new Conn {
                                Name = strArray2[0].Trim(new char[] { ' ', '\t', '\r', '\n' }),
                                User = strArray2[1].Trim(new char[] { ' ', '\t', '\r', '\n' }),
                                Pass = strArray2[2].Trim(new char[] { ' ', '\t', '\r', '\n' }),
                                IP = strArray2[3].Trim(new char[] { ' ', '\t', '\r', '\n' })
                            };
                            this.context.Send(delegate (object d) {
                                ComboBoxItem newItem = new ComboBoxItem {
                                    Content = c.Name + " - " + c.User,
                                    Tag = c
                                };
                                this.comboBoxConnections.Items.Add(newItem);
                            }, null);
                            num++;
                            if (bool.Parse(configuration.AppSettings.Settings["RememberChoise"].Value) && (configuration.AppSettings.Settings["Connection"].Value == (c.Name + " - " + c.User)))
                            {
                                selectIndex = num;
                            }
                        }
                        this.context.Send(d => this.comboBoxConnections.SelectedIndex = selectIndex, null);
                        if (this.comboBoxConnections.Items.Count > 0)
                        {
                            if (callback4 == null)
                            {
                                callback4 = d => this.grid1.Visibility = Visibility.Hidden;
                            }
                            this.context.Send(callback4, null);
                            if (callback5 == null)
                            {
                                callback5 = d => this.grid2.Visibility = Visibility.Visible;
                            }
                            this.context.Send(callback5, null);
                        }
                    }
                    if (str.Contains("nolicense"))
                    {
                        MessageBoxResult none = MessageBoxResult.None;
                        if (this.lang == "ru")
                        {
                            none = MessageBox.Show("Отсутствует GUI Лицензия для этой программы.\nКупите ее на нашем сайте\n\nПерейти на сайт для покупки ?", "Ошибка Мастера", MessageBoxButton.YesNo, MessageBoxImage.Asterisk);
                        }
                        if (this.lang == "en")
                        {
                            none = MessageBox.Show("GUI License is absent for this program.\nBuy it on our web site\n\nGo to the site ?", "Wizard Error", MessageBoxButton.YesNo, MessageBoxImage.Asterisk);
                        }
                        if (none == MessageBoxResult.Yes)
                        {
                            Process.Start("https://thesafety.us/prices_gui/");
                        }
                    }
                    if (str.Contains("nopptp"))
                    {
                        MessageBoxResult result2 = MessageBoxResult.None;
                        if (this.lang == "ru")
                        {
                            result2 = MessageBox.Show("У вас нет активных PPTP VPN подписок.\nВы можете купить их на нашем сайте\n\nПерейти на сайт для покупки ?", "Ошибка Мастера", MessageBoxButton.YesNo, MessageBoxImage.Asterisk);
                        }
                        if (this.lang == "en")
                        {
                            result2 = MessageBox.Show("You have no active PPTP VPN subscriptions.\nYou can buy it on our site\n\nGo to the site for purchasing ?", "Wizard Error", MessageBoxButton.YesNo, MessageBoxImage.Asterisk);
                        }
                        if (result2 == MessageBoxResult.Yes)
                        {
                            Process.Start("https://thesafety.us/billing/");
                        }
                    }
                    if (string.IsNullOrEmpty(str))
                    {
                        MessageBoxResult result3 = MessageBoxResult.None;
                        if (this.lang == "ru")
                        {
                            result3 = MessageBox.Show("Неправильный TheSafety.US логин/пароль.\nЗабыли пароль ? Восстановите пароль на нашем сайте\n\nПерейти на сайт ?", "Ошибка Мастера", MessageBoxButton.YesNo, MessageBoxImage.Asterisk);
                        }
                        if (this.lang == "en")
                        {
                            result3 = MessageBox.Show("Incorrect TheSafety.US login/password.\nForgot password ? Recover password on our site\n\nGo to the site ?", "Wizard Error", MessageBoxButton.YesNo, MessageBoxImage.Asterisk);
                        }
                        if (result3 == MessageBoxResult.Yes)
                        {
                            Process.Start("https://thesafety.us/billing/recover/");
                        }
                    }
                }
                this.context.Send(d => this.grid1.IsEnabled = true, null);
                this.context.Send(d => this.grid2.IsEnabled = true, null);
            }) {
                IsBackground = true
            };
            List<string> parameter = new List<string> {
                this.textBoxLogin.Text,
                this.getPass()
            };
            thread.Start(parameter);
        }

        private void buttonLogin2_Click(object sender, RoutedEventArgs e0)
        {
            Button but = (Button) sender;
            if (but == this.buttonLogin2)
            {
                if (this.lang == "ru")
                {
                    this.labelStatus.Content = "Подключение...";
                }
                if (this.lang == "en")
                {
                    this.labelStatus.Content = "Connection...";
                }
            }
            if (but == this.buttonDisconnect)
            {
                if (this.lang == "ru")
                {
                    this.labelStatus.Content = "Отключение...";
                }
                if (this.lang == "en")
                {
                    this.labelStatus.Content = "Disconnection...";
                }
            }
            this.grid2.IsEnabled = false;
            Thread thread = new Thread(delegate (object ob) {
                SendOrPostCallback callback = null;
                SendOrPostCallback callback2 = null;
                SendOrPostCallback callback3 = null;
                List<string> list = (List<string>) ob;
                Conn c = new Conn();
                if (but == this.buttonLogin2)
                {
                    IPAddress address;
                    if (callback == null)
                    {
                        callback = d => c = (Conn) ((ComboBoxItem) this.comboBoxConnections.SelectedItem).Tag;
                    }
                    this.context.Send(callback, null);
                    System.Configuration.Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                    bool? checkBoxRememberChoiseIsChecked = null;
                    this.context.Send(d => checkBoxRememberChoiseIsChecked = this.checkBoxRememberChoise.IsChecked, null);
                    if (checkBoxRememberChoiseIsChecked.HasValue && checkBoxRememberChoiseIsChecked.Value)
                    {
                        configuration.AppSettings.Settings["Connection"].Value = c.Name + " - " + c.User;
                    }
                    else
                    {
                        configuration.AppSettings.Settings["Connection"].Value = "";
                    }
                    configuration.Save();
                    if (!IPAddress.TryParse(c.IP, out address))
                    {
                        if (this.lang == "ru")
                        {
                            MessageBox.Show("Ошибка распознавания IP адреса", "Ошибка Мастера", MessageBoxButton.OK, MessageBoxImage.Hand);
                        }
                        if (this.lang == "en")
                        {
                            MessageBox.Show("Error of IP address finding", "Wizard Error", MessageBoxButton.OK, MessageBoxImage.Hand);
                        }
                        return;
                    }
                }
                try
                {
                    if (!this.AllUsersPhoneBookOpened)
                    {
                        if ((Environment.OSVersion.Version.Major >= 6) && (Environment.OSVersion.Version.Minor >= 1))
                        {
                            AllUsersPhoneBook.Open(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\Microsoft\Network\Connections\Pbk\rasphone.pbk");
                        }
                        else
                        {
                            AllUsersPhoneBook.Open();
                        }
                        this.AllUsersPhoneBookOpened = true;
                    }
                    List<string> list2 = new List<string>();
                    ReadOnlyCollection<RasConnection> activeConnections = DotRas.RasHelper.GetActiveConnections();
                    foreach (string str in list)
                    {
                        foreach (RasConnection connection in activeConnections)
                        {
                            if (connection.EntryName == str)
                            {
                                connection.HangUp();
                                break;
                            }
                        }
                    }
                    foreach (RasEntry entry in AllUsersPhoneBook.Entries)
                    {
                        foreach (string str2 in list)
                        {
                            if (str2 == entry.Name)
                            {
                                list2.Add(entry.Name);
                            }
                        }
                    }
                    foreach (string str3 in list2)
                    {
                        AllUsersPhoneBook.Entries.Remove(str3);
                    }
                    if (but == this.buttonLogin2)
                    {
                        string name = c.Name + " - " + c.User;
                        RasEntry item = RasEntry.CreateVpnEntry(name, c.IP, RasVpnStrategy.PptpFirst, RasDevice.GetDeviceByName("(PPTP)", "vpn"));
                        AllUsersPhoneBook.Entries.Add(item);
                        item.UpdateCredentials(new NetworkCredential(c.User, c.Pass));
                        RasDialer dialer = new RasDialer();
                        dialer.DialCompleted += new EventHandler<DialCompletedEventArgs>(this.dialer_DialCompleted);
                        dialer.StateChanged += new EventHandler<StateChangedEventArgs>(this.dialer_StateChanged);
                        dialer.EntryName = c.Name + " - " + c.User;
                        dialer.PhoneBookPath = AllUsersPhoneBook.Path;
                        dialer.SynchronizingObject = new DispatcherSynchronizingObject(this.Dispatcher);
                        dialer.DialAsync();
                    }
                    if (but == this.buttonDisconnect)
                    {
                        if (callback2 == null)
                        {
                            callback2 = d => this.grid2.IsEnabled = true;
                        }
                        this.context.Send(callback2, null);
                        if (callback3 == null)
                        {
                            callback3 = d => this.labelStatus.Content = "";
                        }
                        this.context.Send(callback3, null);
                    }
                }
                catch (Exception exception)
                {
                    if (this.lang == "ru")
                    {
                        MessageBox.Show(exception.Message.ToString(), "Ошибка Мастера", MessageBoxButton.OK, MessageBoxImage.Hand);
                    }
                    if (this.lang == "en")
                    {
                        MessageBox.Show(exception.Message.ToString(), "Wizard Error", MessageBoxButton.OK, MessageBoxImage.Hand);
                    }
                }
            });
            List<string> parameter = new List<string>();
            foreach (ComboBoxItem item in (IEnumerable) this.comboBoxConnections.Items)
            {
                parameter.Add(item.Content.ToString());
            }
            thread.Start(parameter);
        }

        private void buttonLogout_Click(object sender, RoutedEventArgs e)
        {
            if (this.lang == "en")
            {
                this.context.Send(d => base.Title = "TheSafety.US PPTP – Authorization", null);
            }
            if (this.lang == "ru")
            {
                this.context.Send(d => base.Title = "TheSafety.US PPTP – Авторизация", null);
            }
            this.grid2.Visibility = Visibility.Hidden;
            this.grid1.Visibility = Visibility.Visible;
        }

        private void buttonUpdateIP_Click(object sender, RoutedEventArgs e)
        {
            new Thread(delegate {
                SendOrPostCallback callback = null;
                SendOrPostCallback callback2 = null;
                SendOrPostCallback callback3 = null;
                SendOrPostCallback callback4 = null;
                string str = new WebClient().DownloadString("https://thesafety.us/billing/gui/ip.php");
                str = str.Trim(new char[] { ' ', '\t', '\r', '\n' });
                if (this.lang == "ru")
                {
                    if (callback == null)
                    {
                        callback = d => this.labelIP.Content = "Ваш IP: " + str;
                    }
                    this.context.Send(callback, null);
                    if (callback2 == null)
                    {
                        callback2 = d => this.icTray.ToolTipText = "TheSafety.US PPTP Client\nВаш IP: " + str;
                    }
                    this.context.Send(callback2, null);
                }
                if (this.lang == "en")
                {
                    if (callback3 == null)
                    {
                        callback3 = d => this.labelIP.Content = "Your IP: " + str;
                    }
                    this.context.Send(callback3, null);
                    if (callback4 == null)
                    {
                        callback4 = d => this.icTray.ToolTipText = "TheSafety.US PPTP Client\nYour IP: " + str;
                    }
                    this.context.Send(callback4, null);
                }
                if (sender.GetType().Name == "MenuItem")
                {
                    if (this.lang == "ru")
                    {
                        this.icTray.ShowBalloonTip("Ваш IP", str, BalloonIcon.Info);
                    }
                    if (this.lang == "en")
                    {
                        this.icTray.ShowBalloonTip("Your IP", str, BalloonIcon.Info);
                    }
                }
            }) { IsBackground = true }.Start();
        }

        private void checkBoxAutoLogin_Click(object sender, RoutedEventArgs e)
        {
            System.Configuration.Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            configuration.AppSettings.Settings["AutoLogin"].Value = this.checkBoxAutoLogin.IsChecked.Value.ToString();
            configuration.Save();
        }

        private void checkBoxRememberChoise_Click(object sender, RoutedEventArgs e)
        {
            System.Configuration.Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            configuration.AppSettings.Settings["RememberChoise"].Value = this.checkBoxRememberChoise.IsChecked.Value.ToString();
            configuration.Save();
        }

        private void checkBoxSavePassword_Click(object sender, RoutedEventArgs e)
        {
            System.Configuration.Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            configuration.AppSettings.Settings["SavePassword"].Value = this.checkBoxSavePassword.IsChecked.Value.ToString();
            if (this.checkBoxSavePassword.IsChecked.HasValue && this.checkBoxSavePassword.IsChecked.Value)
            {
                configuration.AppSettings.Settings["UserSite"].Value = this.textBoxLogin.Text;
                configuration.AppSettings.Settings["PassSite"].Value = EncodeTo64(this.getPass());
            }
            else
            {
                configuration.AppSettings.Settings["UserSite"].Value = "";
                configuration.AppSettings.Settings["PassSite"].Value = "";
            }
            configuration.Save();
        }

        private void checkBoxShowPassword_Click(object sender, RoutedEventArgs e)
        {
            if (this.checkBoxShowPassword.IsChecked.HasValue && this.checkBoxShowPassword.IsChecked.Value)
            {
                this.textBoxPassP.Visibility = Visibility.Hidden;
                this.textBoxPassT.Text = this.textBoxPassP.Password;
                this.textBoxPassT.Visibility = Visibility.Visible;
            }
            else
            {
                this.textBoxPassT.Visibility = Visibility.Hidden;
                this.textBoxPassP.Password = this.textBoxPassT.Text;
                this.textBoxPassP.Visibility = Visibility.Visible;
            }
            System.Configuration.Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            configuration.AppSettings.Settings["ShowPassword"].Value = this.checkBoxShowPassword.IsChecked.Value.ToString();
            configuration.Save();
        }

        public void CheckLang()
        {
            if (this.lang == "en")
            {
                base.Title = "TheSafety.US PPTP - Authorization";
                this.label1.Content = "Choose PPTP Subscription from the list below:";
                this.checkBoxRememberChoise.Content = "Remember choise";
                this.labelLogin.Content = "Login:";
                this.labelPassword.Content = "Password:";
                this.checkBoxShowPassword.Content = "Show password";
                this.checkBoxSavePassword.Content = "Save password";
                this.checkBoxAutoLogin.Content = "Auto login";
                this.labelForgot.Text = "Forgot your password ?";
                this.labelRegistration.Text = "Registration";
                this.buttonLogin.ToolTip = "Login";
                this.buttonUpdate.ToolTip = "Update";
                this.buttonLogin2.ToolTip = "Connect";
                this.buttonLogout.ToolTip = "Logout";
                this.MenuItemShow.Header = "Show";
                this.MenuItemExit.Header = "Exit";
                this.buttonDisconnect.ToolTip = "Disconnect";
                this.buttonUpdateIP.ToolTip = "Check IP";
                this.MenuItemCheckIP.Header = "Check IP";
            }
            if (this.lang == "ru")
            {
                base.Title = "TheSafety.US PPTP - Авторизация";
                this.label1.Content = "Выберите PPTP подписку из списка ниже:";
                this.checkBoxRememberChoise.Content = "Запомнить выбор";
                this.labelLogin.Content = "Логин:";
                this.labelPassword.Content = "Пароль:";
                this.checkBoxShowPassword.Content = "Показать пароль";
                this.checkBoxSavePassword.Content = "Сохранить пароль";
                this.checkBoxAutoLogin.Content = "Авто вход";
                this.labelForgot.Text = "Забыли ваш пароль ?";
                this.labelRegistration.Text = "Регистрация";
                this.buttonLogin.ToolTip = "Вход";
                this.buttonUpdate.ToolTip = "Обновить";
                this.buttonLogin2.ToolTip = "Подключить";
                this.buttonLogout.ToolTip = "Выход";
                this.MenuItemShow.Header = "Показать";
                this.MenuItemExit.Header = "Выход";
                this.buttonDisconnect.ToolTip = "Отключить";
                this.buttonUpdateIP.ToolTip = "Проверить IP";
                this.MenuItemCheckIP.Header = "Проверить IP";
            }
        }

        private void comboBoxLang_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            System.Configuration.Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            configuration.AppSettings.Settings["Language"].Value = ((ComboBoxItem) this.comboBoxLang.SelectedItem).Tag.ToString();
            configuration.Save();
            this.lang = ((ComboBoxItem) this.comboBoxLang.SelectedItem).Tag.ToString();
            this.CheckLang();
        }

        private static string DecodeFrom64(string encodedData)
        {
            if (string.IsNullOrEmpty(encodedData))
            {
                return encodedData;
            }
            byte[] bytes = Convert.FromBase64String(encodedData);
            return Encoding.ASCII.GetString(bytes);
        }

        private void dialer_DialCompleted(object sender, DialCompletedEventArgs e)
        {
            this.grid2.IsEnabled = true;
            if (!e.Cancelled)
            {
                if (e.Connected)
                {
                    if (this.lang == "ru")
                    {
                        this.labelStatus.Content = "Подключено (" + ((ComboBoxItem) this.comboBoxConnections.SelectedItem).Content.ToString() + ")";
                    }
                    if (this.lang == "en")
                    {
                        this.labelStatus.Content = "Connected (" + ((ComboBoxItem) this.comboBoxConnections.SelectedItem).Content.ToString() + ")";
                    }
                }
                else if (e.Error != null)
                {
                    this.labelStatus.Content = "";
                    if (this.lang == "ru")
                    {
                        MessageBox.Show(e.Error.Message, "Ошибка Мастера", MessageBoxButton.OK, MessageBoxImage.Hand);
                    }
                    if (this.lang == "en")
                    {
                        MessageBox.Show(e.Error.Message, "Wizard Error", MessageBoxButton.OK, MessageBoxImage.Hand);
                    }
                }
                else if (e.TimedOut)
                {
                    this.labelStatus.Content = "";
                }
            }
        }

        private void dialer_StateChanged(object sender, StateChangedEventArgs e)
        {
        }

        private static string EncodeTo64(string encodedData)
        {
            return Convert.ToBase64String(Encoding.ASCII.GetBytes(encodedData));
        }

        private string getPass()
        {
            if (this.textBoxPassP.Visibility == Visibility.Visible)
            {
                return this.textBoxPassP.Password;
            }
            if (this.textBoxPassT.Visibility == Visibility.Visible)
            {
                return this.textBoxPassT.Text;
            }
            return "";
        }

        [DebuggerNonUserCode]
        public void InitializeComponent()
        {
            if (!this._contentLoaded)
            {
                this._contentLoaded = true;
                Uri resourceLocator = new Uri("/thesafetyuspptp;component/mainwindow.xaml", UriKind.Relative);
                Application.LoadComponent(this, resourceLocator);
            }
        }

        private void labelForgot_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            Process.Start("https://thesafety.us/billing/recover/");
        }

        private void labelRegistration_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            Process.Start("https://thesafety.us/billing/signup/");
        }

        private void MenuItemExit_Click(object sender, RoutedEventArgs e)
        {
            base.Close();
        }

        private void MenuItemShow_Click(object sender, RoutedEventArgs e)
        {
            this.icTray.Visibility = Visibility.Hidden;
            base.Show();
            base.WindowState = WindowState.Normal;
            base.Activate();
        }

        [EditorBrowsable(EditorBrowsableState.Never), DebuggerNonUserCode]
        void IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
                case 1:
                    ((MainWindow) target).ContentRendered += new EventHandler(this.Window_ContentRendered);
                    ((MainWindow) target).Loaded += new RoutedEventHandler(this.Window_Loaded);
                    ((MainWindow) target).Closing += new CancelEventHandler(this.Window_Closing);
                    ((MainWindow) target).StateChanged += new EventHandler(this.Window_StateChanged);
                    return;

                case 2:
                    this.icTray = (TaskbarIcon) target;
                    return;

                case 3:
                    this.MenuItemShow = (MenuItem) target;
                    this.MenuItemShow.Click += new RoutedEventHandler(this.MenuItemShow_Click);
                    return;

                case 4:
                    this.MenuItemCheckIP = (MenuItem) target;
                    this.MenuItemCheckIP.Click += new RoutedEventHandler(this.buttonUpdateIP_Click);
                    return;

                case 5:
                    this.MenuItemExit = (MenuItem) target;
                    this.MenuItemExit.Click += new RoutedEventHandler(this.MenuItemExit_Click);
                    return;

                case 6:
                    this.grid1 = (Grid) target;
                    return;

                case 7:
                    this.image2 = (Image) target;
                    return;

                case 8:
                    this.labelLogin = (Label) target;
                    return;

                case 9:
                    this.labelPassword = (Label) target;
                    return;

                case 10:
                    this.textBoxLogin = (TextBox) target;
                    this.textBoxLogin.KeyUp += new KeyEventHandler(this.textBoxLoginPass_KeyUp);
                    return;

                case 11:
                    this.textBoxPassP = (PasswordBox) target;
                    this.textBoxPassP.KeyUp += new KeyEventHandler(this.textBoxLoginPass_KeyUp);
                    this.textBoxPassP.GotFocus += new RoutedEventHandler(this.textBoxPass_GotFocus);
                    return;

                case 12:
                    this.textBoxPassT = (TextBox) target;
                    this.textBoxPassT.KeyUp += new KeyEventHandler(this.textBoxLoginPass_KeyUp);
                    this.textBoxPassT.GotFocus += new RoutedEventHandler(this.textBoxPass_GotFocus);
                    return;

                case 13:
                    this.comboBoxLang = (ComboBox) target;
                    this.comboBoxLang.SelectionChanged += new SelectionChangedEventHandler(this.comboBoxLang_SelectionChanged);
                    return;

                case 14:
                    this.checkBoxShowPassword = (CheckBox) target;
                    this.checkBoxShowPassword.Click += new RoutedEventHandler(this.checkBoxShowPassword_Click);
                    return;

                case 15:
                    this.checkBoxSavePassword = (CheckBox) target;
                    this.checkBoxSavePassword.Click += new RoutedEventHandler(this.checkBoxSavePassword_Click);
                    return;

                case 0x10:
                    this.checkBoxAutoLogin = (CheckBox) target;
                    this.checkBoxAutoLogin.Click += new RoutedEventHandler(this.checkBoxAutoLogin_Click);
                    return;

                case 0x11:
                    this.labelForgot = (TextBlock) target;
                    this.labelForgot.MouseLeftButtonUp += new MouseButtonEventHandler(this.labelForgot_MouseLeftButtonUp);
                    return;

                case 0x12:
                    this.labelRegistration = (TextBlock) target;
                    this.labelRegistration.MouseLeftButtonUp += new MouseButtonEventHandler(this.labelRegistration_MouseLeftButtonUp);
                    return;

                case 0x13:
                    this.buttonLogin = (Button) target;
                    this.buttonLogin.Click += new RoutedEventHandler(this.buttonLogin_Click);
                    return;

                case 20:
                    this.grid2 = (Grid) target;
                    return;

                case 0x15:
                    this.label1 = (Label) target;
                    return;

                case 0x16:
                    this.comboBoxConnections = (ComboBox) target;
                    return;

                case 0x17:
                    this.buttonUpdate = (Button) target;
                    this.buttonUpdate.Click += new RoutedEventHandler(this.buttonLogin_Click);
                    return;

                case 0x18:
                    this.checkBoxRememberChoise = (CheckBox) target;
                    this.checkBoxRememberChoise.Click += new RoutedEventHandler(this.checkBoxRememberChoise_Click);
                    return;

                case 0x19:
                    this.buttonLogout = (Button) target;
                    this.buttonLogout.Click += new RoutedEventHandler(this.buttonLogout_Click);
                    return;

                case 0x1a:
                    this.buttonLogin2 = (Button) target;
                    this.buttonLogin2.Click += new RoutedEventHandler(this.buttonLogin2_Click);
                    return;

                case 0x1b:
                    this.labelStatus = (Label) target;
                    return;

                case 0x1c:
                    this.buttonDisconnect = (Button) target;
                    this.buttonDisconnect.Click += new RoutedEventHandler(this.buttonLogin2_Click);
                    return;

                case 0x1d:
                    this.buttonUpdateIP = (Button) target;
                    this.buttonUpdateIP.Click += new RoutedEventHandler(this.buttonUpdateIP_Click);
                    return;

                case 30:
                    this.labelIP = (Label) target;
                    return;
            }
            this._contentLoaded = true;
        }

        private void textBoxLoginPass_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Return)
            {
                this.buttonLogin_Click(null, null);
            }
        }

        private void textBoxPass_GotFocus(object sender, RoutedEventArgs e)
        {
            if (sender.GetType().Name == "PasswordBox")
            {
                ((PasswordBox) sender).SelectAll();
            }
            if (sender.GetType().Name == "TextBox")
            {
                ((TextBox) sender).SelectAll();
            }
        }

        private void Window_Closing(object sender, CancelEventArgs e)
        {
            this.checkBoxSavePassword_Click(null, null);
        }

        private void Window_ContentRendered(object sender, EventArgs e)
        {
            System.Configuration.Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            this.checkBoxShowPassword.IsChecked = new bool?(bool.Parse(configuration.AppSettings.Settings["ShowPassword"].Value));
            this.checkBoxSavePassword.IsChecked = new bool?(bool.Parse(configuration.AppSettings.Settings["SavePassword"].Value));
            this.checkBoxAutoLogin.IsChecked = new bool?(bool.Parse(configuration.AppSettings.Settings["AutoLogin"].Value));
            this.checkBoxRememberChoise.IsChecked = new bool?(bool.Parse(configuration.AppSettings.Settings["RememberChoise"].Value));
            if (this.checkBoxShowPassword.IsChecked.HasValue && this.checkBoxShowPassword.IsChecked.Value)
            {
                this.textBoxPassP.Visibility = Visibility.Hidden;
                this.textBoxPassT.Visibility = Visibility.Visible;
            }
            else
            {
                this.textBoxPassT.Visibility = Visibility.Hidden;
                this.textBoxPassP.Visibility = Visibility.Visible;
            }
            if (this.checkBoxSavePassword.IsChecked.HasValue && this.checkBoxSavePassword.IsChecked.Value)
            {
                this.textBoxLogin.Text = configuration.AppSettings.Settings["UserSite"].Value;
                this.textBoxPassP.Password = DecodeFrom64(configuration.AppSettings.Settings["PassSite"].Value);
                this.textBoxPassT.Text = DecodeFrom64(configuration.AppSettings.Settings["PassSite"].Value);
            }
            this.textBoxLogin.Focus();
            if (this.checkBoxAutoLogin.IsChecked.HasValue && this.checkBoxAutoLogin.IsChecked.Value)
            {
                this.buttonLogin_Click(null, null);
            }
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            this.context = SynchronizationContext.Current;
        }

        private void Window_StateChanged(object sender, EventArgs e)
        {
            if (base.WindowState == WindowState.Minimized)
            {
                this.icTray.Visibility = Visibility.Visible;
                base.Hide();
            }
        }

        private string zapros(string login, string pass)
        {
            WebResponse response = null;
            WebRequest request = null;
            Stream requestStream = null;
            Stream responseStream = null;
            StreamReader reader = null;
            string str = "";
            bool flag = false;
            try
            {
                request = WebRequest.Create("https://thesafety.us/billing/gui/guip.php");
                request.Method = "POST";
                request.Timeout = 0x1d4c0;
                request.ContentType = "application/x-www-form-urlencoded";
                byte[] bytes = null;
                string str2 = string.Empty;
                foreach (byte num in new MD5CryptoServiceProvider().ComputeHash(Encoding.Default.GetBytes(pass)))
                {
                    str2 = str2 + num.ToString("X2");
                }
                bytes = Encoding.GetEncoding(0x4e3).GetBytes("deistvo=download&glog80=" + login + "&rpass3t=" + str2);
                request.ContentLength = bytes.Length;
                requestStream = request.GetRequestStream();
                requestStream.Write(bytes, 0, bytes.Length);
                requestStream.Close();
                response = request.GetResponse();
                responseStream = response.GetResponseStream();
                Encoding encoding = Encoding.GetEncoding(0x4e3);
                reader = new StreamReader(responseStream, encoding);
                char[] buffer = new char[0x100];
                int length = reader.Read(buffer, 0, 0x100);
                string str3 = "";
                while (length > 0)
                {
                    string str4 = new string(buffer, 0, length);
                    str3 = str3 + str4;
                    length = reader.Read(buffer, 0, 0x100);
                }
                str = str3;
            }
            catch (Exception exception)
            {
                flag = true;
                if (this.lang == "ru")
                {
                    MessageBox.Show(exception.Message, "Ошибка Мастера", MessageBoxButton.OK, MessageBoxImage.Hand);
                }
                if (this.lang == "en")
                {
                    MessageBox.Show(exception.Message, "Wizard Error", MessageBoxButton.OK, MessageBoxImage.Hand);
                }
            }
            finally
            {
                if (requestStream != null)
                {
                    requestStream.Close();
                }
                if (responseStream != null)
                {
                    responseStream.Close();
                }
                if (reader != null)
                {
                    reader.Close();
                }
                if (response != null)
                {
                    response.Close();
                }
            }
            if (flag)
            {
                return "isError";
            }
            return str;
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct Conn
        {
            public string Name;
            public string User;
            public string Pass;
            public string IP;
        }
    }
}

